using UnityEngine;
using QFramework;
using UnityEngine.UI;

namespace Projectsurviva
{
	public partial class FloatingtextContoller : ViewController
	{
		void Start()
		{
			// Code Here
			FloatingText.Hide();
		}
		static FloatingtextContoller mdefault;
        private void Awake()
        {
            mdefault = this;
        }
        private void OnDestroy()
        {
            mdefault = null;
        }
        public static  void Play(Vector2 pos,string text,bool critical=false)
        {
            mdefault.FloatingText.InstantiateWithParent(mdefault.transform).Position(pos.x,pos.y).Self(f => 
            {
                var positionY = pos.y;

                var texttrans = f.transform.Find("text");
                var textcomp = texttrans.GetComponent<Text>();
                textcomp.text = text;
                if(critical)
                {
                    textcomp.color = Color.red;

                }
                ActionKit.Sequence() .Lerp(0, 0.5f, 0.5f, (p) =>
                {
                    f.PositionY(positionY + p*0.25f);
                    textcomp.LocalScaleX(Mathf.Clamp01(p*8));
                    textcomp.LocalScaleY(Mathf.Clamp01( p *8));

                }
                ).Delay(0.5f).Lerp(1.0f,0, 0.3f, (p) => 
                {
                    textcomp.ColorAlpha(p);
                    texttrans.DestroyGameObjGracefully();
                }, () => { }
                ).Start(textcomp);

            
            }).Show() ;

        }
    }
}
